package com.wwz.leetcode;

import org.junit.Test;

public class LeetCode35 {
    public int searchInsert(int[] nums, int target) {
        int length = nums.length;
        int index = length;
        if (length == 0) {
            return index;
        }
        int left = 0;
        int right = length - 1;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            if (nums[mid] == target) {
                return mid;
            }
            if (nums[mid] > target) {
                index = mid;
                right = mid - 1;

            } else {
                left = mid + 1;
            }

        }
        return index;
    }

    @Test
    public void test() {
        System.out.println(searchInsert(new int[]{1,3,5,6}, 7));

    }
}
